<template>
  <el-form ref="form" :model="userConfig" label-width="180px" size="large">
    <el-form-item label="钉钉机器人Webhook">
      <el-input v-model="userConfig.dingAccessToken" placeholder="注意是webhook中access_token后面的内容（即不包含https及域名等信息）"></el-input>
    </el-form-item>
    <el-form-item label="钉钉机器人密钥">
      <el-input v-model="userConfig.dingSign" placeholder="机器人安全设置为加签（此处为加签后的密钥）"></el-input>
    </el-form-item>
    <el-form-item size="large">
      <el-button type="primary" @click="onSubmit">确认</el-button>
      <el-button type="warning" @click="testDing">测试连接</el-button>
    </el-form-item>
  </el-form>
</template>

<script>
export default {
  name: "LicenseUserConfig",
  data() {
    return {
      userConfig: {
        dingAccessToken: '',
        dingSign: ''
      }
    };
  },
  methods: {
    async onSubmit() {
      console.log('submit!');
      let res = await this.$http.post('/api/licenseUserConfig/update', this.userConfig)
      if(res.code == 0){
        this.$message({
          message: res.message,
          type: 'success'
        })
      }else {
        this.$message({
          message: res.message,
          type: 'error'
        })
      }
    },
    async getUserConfig() {
      let res = await this.$http.get('/api/licenseUserConfig/getMyConfig')
      this.userConfig.dingAccessToken = res.data.dingAccessToken
      this.userConfig.dingSign = res.data.dingSign
    },
    async testDing() {
      let res = await this.$http.post('/api/licenseUserConfig/testDing', this.userConfig)
      if(res.code == 0){
        this.$message({
          message: res.message,
          type: 'success'
        })
      }else {
        this.$message({
          message: res.message,
          type: 'error'
        })
      }
    }
  },
  created: function(){
    this.getUserConfig()
  }
}
</script>

<style lang="scss" scoped>

</style>
